package com.flash.TAManagement.service.impl;


import com.flash.TAManagement.entity.Ta;
import com.flash.TAManagement.mapper.TaMapper;
import com.flash.TAManagement.service.TaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TaServiceImpl implements TaService {
    @Autowired
    private TaMapper taMapper;

    //查询
    @Override
    public List<Ta> selectTa(int page , int limit,String businessTime,String dealType) {
        Map map = new HashMap();
        map.put("strWhere",strWhere(businessTime,dealType));
        map.put("strPage",(page - 1)*limit);
        map.put("strLimit",limit);
        return taMapper.selectTa(map);
    }

    @Override
    public int selectTaCount() {
        return taMapper.selectTaCount();
    }
    private String strWhere(String businessTime, String dealType){
        StringBuffer buffer = new StringBuffer();
        if (businessTime!=null && !businessTime.equals("")){
            buffer.append(" and dealTime like '%"+businessTime+"%'");
        }
        if (dealType!=null && !dealType.equals("")){
            buffer.append(" and dealType like '%"+dealType+"%'");
        }
        System.out.println("拼接的sql语句为:"+buffer.toString());
        return buffer.toString();
    }
    //增加
    @Override
    public int insertTa(Ta ta) {
        return taMapper.insertTa(ta);
    }

    //删除
    @Override
    public int deleteTa(String taId) {
        return taMapper.deleteTa(taId);
    }

    @Override
    //修改
    public int updateTa(Ta ta) {
        return taMapper.updateTa(ta);
    }
}
